
#include "Unit.h"

const unsigned int BASE_UNIT_COEFFICIENT(1);
const unsigned int NUM_OF_UNIT(6);
const int EXCEPTION_USER_IS_NOT_ALLOWED_TO_DEFINE_A_NEW_UNIT(3);

UnitType::UnitType()
{
}

bool UnitType::operator==(const UnitType &unitType) const
{
    return this == &unitType;
}

bool UnitType::operator!=(const UnitType &unitType) const
{
    return !(*this == unitType);
}

Unit::Unit(unsigned int unit, const UnitType &unitType) throw(int)
:
unitCoefficient(unit),
unitType(unitType)
{
    if(numOfUnit >= NUM_OF_UNIT)
    {
        throw int(EXCEPTION_USER_IS_NOT_ALLOWED_TO_DEFINE_A_NEW_UNIT);
    }
    numOfUnit ++;
}

unsigned int Unit::getValueInBaseUnit(unsigned int amount) const
{
    return amount * unitCoefficient;
}

int Unit::numOfUnit = 0;

bool Unit::isInSameType(const Unit &unit) const
{
    return unitType == unit.unitType;
}

bool Unit::operator<=(const Unit &unit) const
{
	return unitCoefficient <= unit.unitCoefficient;
}

unsigned int Unit::operator/(const Unit &unit) const
{
	return unitCoefficient / unit.unitCoefficient;
}


